package ch.ti.bfh.app.loodel.domain.timeslotvote;

import ch.ti.bfh.app.loodel.domain.member.Member;
import ch.ti.bfh.app.loodel.internal.repository.GlobalRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;

import java.util.List;

public interface TimeSlotVoteRepository extends GlobalRepository<TimeSlotVote, Long> {

    List<TimeSlotVote> findTimeSlotVotesByTimeSlot_Id(Long timeSlotId);

    @Query("Select vote.voter From TimeSlotVote as vote where vote.timeSlot.id = :timeSlotId")
    List<Member> findAllVotedMemberForTimeSlot(@Param("timeSlotId") Long timeSlotId);

    @Query("Select Distinct vote.voter From TimeSlotVote as vote where vote.timeSlot.learningEvent.id = :learningEventId")
    List<Member> findAllVotedMembersForLearningEvent(@Param("learningEventId") String learningEventId);

    @Query("Select vote From TimeSlotVote as vote where vote.timeSlot.id = :timeSlotId and vote.voter.id = :memberId")
    TimeSlotVote findByTimeSlotIdAndMemberId(@Param("timeSlotId") Long timeSlotId, @Param("memberId") Long memberId);
}
